@extends('layouts.back_stage')
@section('content')
    <style>
        .edit_li:nth-of-type(2),.edit_li:nth-of-type(3),.edit_li:nth-of-type(4),.edit_li:nth-of-type(5),.edit_li:nth-of-type(6){padding:10px 0;}
        .edit_li:nth-of-type(7){padding:20px 0;}
        .edit_li img{width:60px;height:60px;margin-left:20px;}
        .edit_li span,.edit_li .colors{margin-left:20px;}
        .edit_li .areaTxt{margin-left:20px;resize:none;width:400px;height:150px;}
        .lbl_btn{float: left;margin-left:405px;}
    </style>
    <div class="container">
        <div class="row">
            <div style="margin: 30px;"><h3 >编辑</h3></div>
            <div class="col-md-10 col-md-offset-1">
                <div class="form-group">
                    <ul class="edit_ul">
                        <li class="edit_li"><label>图片：</label><img src="{{ env('CDN_DOMAIN_NAME') }}/upload/{{ $order->face }}"></li>
                        <li class="edit_li"><label>品牌：</label><span>{{ $brand[$order->brand_id] }}</span></li>
                        <li class="edit_li"><label>名称：</label><span>{{ $product->title }}</span></li>
                        <li class="edit_li"><label>款号：</label><span>{{ $order->girard }}</span></li>
                        <li class="edit_li"><label>数量：</label><span>{{ $order->num }} /手</span></li>
                        <li class="edit_li">
                            <label>颜色：</label>
                            @foreach($color as $k => $v)
                                @if($v['stock'] == 0)
                                    <lable>
                                        <input name="color"  type="radio" value="{{ $k }}"
                                          @if($k == $order->color_id) checked @endif
                                          class="colors" disabled> {{ $v['color'] }}(剩{{ $v['stock'] }}手)
                                    </lable>
                                @else
                                    <lable>
                                        <input name="color" type="radio" value="{{ $k }}"
                                          @if($k == $order->color_id) checked @endif
                                          @if($order->status == -3) disabled @endif
                                          class="colors"> {{ $v['color'] }}(剩{{ $v['stock'] }}手)
                                    </lable>
                                @endif
                            @endforeach
                        </li>
                        <li class="edit_li">
                            <label style="float:left;">备注：</label>
                            <textarea name="" class="areaTxt">{{ $order->remarks }}</textarea>
                        </li>
                    </ul>
                </div>
                <div class="form-group">
                    <button type='submit' class='btn btn-success lbl_btn'>保存</button>
                </div>
            </div>
        </div>
    </div>
    @include('errors.list')
    <script>
        $(document).on("click",".lbl_btn",function(){
            var page='{{ $_GET['page'] }}';
            var id='{{ $_GET['id'] }}';
            var remarks=$(".areaTxt").val();
            for(var i=0; i< $(".colors").length;i++){
                if($(".colors")[i].checked){
                    var color_id=$(".colors")[i].value;
                }
            }
            $.ajax({
                headers: {'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                url:'/order/updateOrderColor',
                data:{'id':id,'color_id':color_id,'remarks':remarks},
                type:'post',
                dataType: 'json',
                success:function (data) {
                    if(data.success) {
                        $(".faceImg").attr("src","/img/laugh.png");
                        $(".oHandle").text("修改成功");
                        $(".oSuccess").show(0).delay(1000).hide(0);
                        window.location.href="/order?page="+page;
                    }else {
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            })

        })
    </script>
@endsection